(function () {
    "use strict";

    angular.module('core').factory('servicoIntegracaoService', factory);
    factory.$inject = ['$http', '$q'];

    function factory($http, $q) {

        var _get = function (id) {
            var deferred = $q.defer();
            var args = { id: id };
            $http.post('/servicointegracao/get', args)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        };
        var _getAll = function (args) {
            var deferred = $q.defer();
            $http.post('/servicointegracao/getAll', args)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        };
        var _getAllLoja = function (args) {
            var deferred = $q.defer();
            $http.post('/servicointegracao/getAllLoja', args)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        };
        var _save = function (item) {
            var deferred = $q.defer();
            $http.post('/servicointegracao/save', item)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        };

        var _getEventoIntegracao = function (id) {
            var deferred = $q.defer();
            var args = { id: id };
            $http.post('/servicointegracao/getEventoIntegracao', args)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        };
        var _getAllEventoIntegracao = function (args) {
            var deferred = $q.defer();
            $http.post('/servicointegracao/getAllEventoIntegracao', args)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        };
        var _saveEventoIntegracao = function (item) {
            var deferred = $q.defer();
            $http.post('/servicointegracao/saveEventoIntegracao', item)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        };

        var _chartEventoIntegracaoPorDia = function (args) {
            var deferred = $q.defer();
            $http.post('/servicointegracao/chartEventoIntegracaoPorDia', args)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        };

        return {
            get: _get,
            getAll: _getAll,
            getAllLoja: _getAllLoja,
            save: _save,
            getEventoIntegracao: _getEventoIntegracao,
            getAllEventoIntegracao: _getAllEventoIntegracao,
            saveEventoIntegracao: _saveEventoIntegracao,
            chartEventoIntegracaoPorDia: _chartEventoIntegracaoPorDia
        };
    }

})();


